/*
 * Copyright (c) 2016. jiiiiiin 15398699939@163.com
 */

package com.bankscene.screenfit.util;

import java.util.LinkedList;

public class Stack<T> {
    private LinkedList<T> storage = new LinkedList<T>();

    /**
     * 入栈
     */
    public void push(T v) {
        storage.addFirst(v);
    }

    /**
     * 出栈，但不删除
     */
    public T peek() {
        return storage.getFirst();
    }

    /**
     * 出栈，删除
     */
    public T pop() {
        return storage.removeFirst();
    }

    /**
     * 栈是否为空
     */
    public boolean empty() {
        return storage.isEmpty();
    }

    public int size() {
        return storage.size();
    }

    /**
     * 打印栈元素
     */
    public String toString() {
        return storage.toString();
    }

    public static void main(String[] args) {
        Stack stack = new Stack<String>();
        stack.push("a");
        stack.push("b");
        stack.push("c");
        //[c, b, a]
        System.out.println(stack.toString());
        //c--[c, b, a]
        Object obj = stack.peek();
        System.out.println(obj + "--" + stack.toString());
        obj = stack.pop();
        //c--[b, a]
        System.out.println(obj + "--" + stack.toString());
        //false
        System.out.println(stack.empty());
    }
}
